<!DOCTYPE html>
<html>

<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>添加航班信息</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <link rel="stylesheet" href="../css/add_flight.css">
    
	<script src="../plugins/jQuery/jquery-2.2.3.min.js"></script>
	
	<!-- 1、引入angular.js-->
	<script src="../plugins/angularjs/angular.min.js"></script>
	<script src="../js/plugins/requjest/request.js"></script>
    <script src="../js/controller/flightManageController.js"></script>
    
</head>

<body>
	<div class="title" >
		<label>添加航班</label>
	</div>
	<div class="content" id="Flight">
		<div class="content-inner">
		 <table width="100%" height="100%" style="border-collapse: collapse;"
			border="0" cellpadding="0" cellspacing="0">
			<tr class="line line1">
				<td colspan="3"><label>基本信息</label></td>
			</tr>
			<tr class="line line2">
				<td colspan="3"></td>
			</tr>
			<tr class="line">
				<td colspan="3">
					<label>航班号</label>
				    <input  placeholder="例：C919" v-model="flight.flightNumber" >
				</td>
			</tr>
			<tr class="line">
				<td>
					<label>起点</label>
				    <input placeholder="例：北京" v-model="flight.flightStartPlace"  >
				</td>
				<td>
					<label>终点</label>
				    <input placeholder="例：成都" v-model="flight.flightEndPlace" >
				</td>
				<td>
					<label>始发机场</label>
				    <input  placeholder="例：北京机场" v-model="flight.flightStartAirport" >
				</td>
			</tr>
			<tr class="line">
				<td>
					<label>到达机场</label>
				    <input placeholder="例：成都机场" v-model="flight.flightEndAirport" >
				</td>
				<td>
					<label>起飞时间</label>
				    <input type="datetime-local"  v-model="flight.flightStartTime" />
				</td>
				<td>
					<label>到达时间</label>
				    <input  type="datetime-local"  v-model="flight.flightEndTime" />
				</td>
			</tr>
			<tr class="line">
				<td>
					<label>头等舱价格</label>
				    <input type="number" min="1" step="0.1"  placeholder="例：2100" v-model="flight.flightHighPrice" >
				</td>
				<td>
					<label>头等舱座位数</label>
				    <input type="number" min="0"  placeholder="例：200" v-model="flight.flightHighNum" >
				</td>
				<td>
					<label>商务舱价格</label>
				    <input type="number" min="1" step="0.1"  placeholder="例：2100" v-model="flight.flightMiddlePrice" >
				</td>
			</tr>
			<tr class="line">
				<td>
					<label>商务舱座位数</label>
				    <input type="number" min="0"placeholder="例：200" v-model="flight.flightMiddleNum" >
				</td>

			</tr>
			<!--用于填充-->
			<tr class="line line2">
				<td colspan="3"></td>
			</tr>
		</table>
	 </div>
	 <!--保存按钮-->
	 <button class="save" @click="add">保存</button>
	</div>
	

</body>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<!-- 官网提供的 axios 在线地址 -->
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script type="text/javascript">
	new Vue({
		el:"#Flight",
		data() {
			return {
				id:'',
				flight:{
					flightId:[],
					flightEndAirport:[],
					flightEndPlace:[],
					flightEndTime:[],
					flightHighNum:[],
					flightHighPrice:[],
					flightMiddleNum:[],
					flightMiddlePrice:[],
					flightNumber:[],
					flightStartAirport:[],
					flightStartPlace:[],
					flightStartTime:[],

				},
				addOrUpdate:'add',

			}
		},
		created(){
			this.id=requestUrlParam('id')

			if(this.id){
				this.addOrUpdate='update'
				this.flight.flightid=this.id
				this.init()
			}
		},
		methods:{
			//aixos 会返回一个Promise对象
			//async 和 await 基于 promise 的。
			//   使用 async 的函数将会始终返回一个 promise 对象
			//   await 关键字只能放到async 函数里面


			async init() {


				await  GetEdit(this.id).then(res => {
					alert(this.id)
					console.log(res.data.data)
					this.flight=res.data.data

				}).catch(err => {
					alert("cuowu")
				})
			},


			async add(){
				if (this.addOrUpdate==='update'){
					let res =await Update(this.flight);
					if (String(res.data.code) === '1'){
						console.log(res)
						alert("修改成功")
						window.location.href= 'list_light.html'
					}else{
						alert(res.data.msg)
					}
				}else{

					let res =await SaveFlight(this.flight);
					if (String(res.data.code) === '1'){
						alert("添加成功")
						window.location.href= 'list_light.html'
					}else{
						alert(res.data.msg)
					}
				}
			},

		}

	})




</script>
</html>